﻿namespace _087.HostedService托管服务
{
    public class HostedService1 : BackgroundService
    {
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            try
            {
                await Console.Out.WriteLineAsync("HostedService1 启动");
                await Task.Delay(3000);
                string file = await File.ReadAllTextAsync("d:/1.txt");
                await Console.Out.WriteLineAsync("文件读取完成");
                await Task.Delay(3000);
                await Console.Out.WriteLineAsync(file);
            }
            catch (Exception ex)
            {
                await Console.Out.WriteLineAsync("服务出现异常");
            }
        }
    }
}
